package com.tuanzi.loan.web.bean.family.largeamount;

import com.tuanzi.loan.business.entity.family.LoanLargeAmountNewPartnerInfo;
import com.tuanzi.loan.business.service.family.LoanChannelNdInfoService;
import com.tuanzi.loan.business.service.family.LoanLargeAmountNewPartnerInfoService;
import com.tuanzi.loan.vo.request.Collaborate.LargeAmountNewPartnerRequest;
import com.tuanzi.loan.vo.response.collaborate.LargeAmountNewPartnerResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.family.largeAmount.LoanLargeAmountNewPartnerInfoListLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;

/**
 * User: liangZongXi
 * Create time: 11:19 2019/8/21
 * Description:
 */

@Data
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanLargeAmountNewPartnerInfoListBean extends JSFListingBean<LargeAmountNewPartnerRequest, LargeAmountNewPartnerResponse> {
    private static final long serialVersionUID = -2069302396203742868L;
    private List<String> channelNdInfos;

    @Autowired
    private LoanChannelNdInfoService loanChannelNdInfoService;
    @Autowired
    private LoanLargeAmountNewPartnerInfoService loanLargeAmountNewPartnerInfoService;

    @PostConstruct
    private void init(){
        initLazyDataModel();
        this.channelNdInfos = loanChannelNdInfoService.findDistinctChannelNd();
    }

    private void initLazyDataModel() {
        $ = new LargeAmountNewPartnerRequest();
        lazyDataModel = new LoanLargeAmountNewPartnerInfoListLazyDataModel($);
    }

    public void onRest(){
        initLazyDataModel();
    }

    public String toAdd(){
        return redirect("/views/family/WholeSaleManage/largePartnerInfo.xhtml");
    }

    public String toEdit(Long id){
        return redirect("/views/family/WholeSaleManage/largePartnerInfo.xhtml?id=" + id);
    }

    public void onDelete(Long id){
        LoanLargeAmountNewPartnerInfo one = loanLargeAmountNewPartnerInfoService.findOne(id);
        if(null != one){
            loanLargeAmountNewPartnerInfoService.delete(one);
            initLazyDataModel();
            addSuccessfullyMessage();
        }
    }

}
